#!/bin/bash

# 安装进度
echo "开始安装wrk..."
echo "正在下载wrk..."

# 下载wrk
if git clone https://gitee.com/geekyu/wrk.git;  then
  echo "wrk下载成功！"
else
  echo "wrk下载失败！"
  exit 1
fi

echo "正在安装依赖..."

# 安装依赖
if sudo yum install -y gcc make openssl-devel; then
  echo "wrk依赖安装成功！"
else
  echo "wrk依赖安装失败！"
  exit 1
fi

echo "开始编译wrk..."

# 编译wrk
if cd wrk && make; then
  echo "wrk编译成功！"
else
  echo "wrk编译失败！"
  exit 1
fi

echo "正在安装wrk..."

# 安装wrk
if sudo cp wrk /usr/local/bin && sudo chmod +x /usr/local/bin/wrk; then
  echo "wrk安装成功！"
else
  echo "wrk安装失败！"
  exit 1
fi

echo "正在配置环境变量..."

# 配置环境变量
if echo 'export PATH=$PATH:/usr/local/bin' >> ~/.bashrc && source ~/.bashrc; then
  echo "环境变量配置成功！"
else
  echo "环境变量配置失败！"
  exit 1
fi

echo "wrk安装完成！"
echo "正在验证wrk是否安装成功..."

# 验证安装
if type wrk >/dev/null 2>&1; then
  echo "wrk安装成功！"
else
  echo "wrk安装失败！"
  exit 1
fi